<template>
	<view class="pl30 pr30 pt30">
		<u-empty text="未添加地址" mode="list" v-if="addList<1"></u-empty>
		<!-- 地址列表 -->
		<uni-swipe-action v-else>
			<block v-for="(item,i) in addList" :key='i'>
				<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(item)" class="mb30">
					<view class="addItemBox flex bg-f col-center " @click="gotoback(item)">
						<block @tap.stop>
							<radio :checked='item.is_default==1' color="#C00000" class="mr30" v-if="item.is_default==1">
							</radio>
							<!-- 右边的盒子 -->
							<view class="flex1">
								<view class="flex">
									<text class="fs26 fw">{{item.name}} {{item.phone}}</text>
									<view class="ml20 defaultbox" v-if="item.is_default==1">
										默认
									</view>
								</view>
								<view class="flex col-center mt10 row-between flex1">
									<view class="flex1 mr30 fs22">{{item.address}}{{item.addr}}</view>
									<text class="cuIcon-post fs40"
										@click.stop="$jump('/subpkg/editAdd/editAdd?from=1&id='+item.id)"></text>
								</view>
							</view>
						</block>
						<!-- //右边的盒子 -->
					</view>
				</uni-swipe-action-item>
				
			</block>

		</uni-swipe-action>


		<!-- 底部的确认按钮 -->
		<view class="footerbtn h88" @click="$jump('/subpkg/editAdd/editAdd?from=2')">
			创建地址
		</view>
	</view>
</template>

<script>
	import uniSwipeAction from '@/uni_modules/uni-swipe-action/components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/uni_modules/uni-swipe-action/components/uni-swipe-action-item/uni-swipe-action-item.vue'
	export default {
		name: 'addlist',
		components: {
			uniSwipeAction,
			uniSwipeActionItem
		},
		onLoad(e) {
			if (e.form) {
				this.form = e.form
			}
		},
		onShow() {
			this.getAddlist()
		},
		data() {
			return {
				options: [{
					//显示文本内容
					text: '删除',
					style: {
						backgroundColor: '#F43535'
					}
				}],
				form: 1,
				addList: [],
				isDefault: false
			};
		},
		methods: {
			getAddlist() {
				this.$api.addlist().then(res => {
					console.log(res)
					this.addList = res.data.data
				})
			},
			gotoback(item) {
				if (this.form == 2) {
					uni.$emit('update', JSON.stringify(item))
					uni.navigateBack()
				}
			},
			swipeActionClickHandler(item) {
				console.log(item)
				this.$api.delAdd({id:item.id}).then(res=>{
					console.log(res)
					this.$msg('删除地址成功')
					this.getAddlist()
				})
			}
		}
	}
</script>

<style lang="scss">
	.addItemBox {
		padding: 30rpx;

		border-radius: 16rpx;

		.defaultbox {
			width: 60rpx;
			height: 34rpx;
			font-size: 18rpx;
			background-color: #F5B927;
			text-align: center;
			line-height: 34rpx;
			color: #FFFFFF;
			border-radius: 4rpx;
		}
	}

	.footerbtn {
		position: fixed;
		width: 90%;
		left: 50%;
		bottom: 60rpx;
		transform: translateX(-50%);
		background: #D23030;
		box-shadow: 0px 2rpx 10rpx 0px rgba(210, 48, 48, 1);
		border-radius: 44rpx;
		font-size: 28rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 88rpx;
	}
</style>
